package org.grapes.wine.api.server.method.sql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.StringTokenizer;

@Deprecated
public class SQLMethods {

	@Deprecated
	public static void readSQL(String sqlStatement, String placeHolder,
			ResultSet[] resultSet) throws SQLException {
		Connection conn = DriverManager
				.getConnection("jdbc:default:connection");

		PreparedStatement prepStmt = conn.prepareStatement(sqlStatement,
				ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
		StringTokenizer stringToken = new StringTokenizer(placeHolder);
		System.out.println("sql: "+sqlStatement);
		System.out.println("ph: "+placeHolder);
		int i = 1;
		while (stringToken.hasMoreTokens()) {
			prepStmt.setString(i, stringToken.nextToken());
			i++;
		}
		resultSet[0] = prepStmt.executeQuery();

		conn.close();
	}

	@Deprecated
	public static void updateSQL(String sqlStatement, String placeHolder) throws SQLException {
		Connection conn = DriverManager
				.getConnection("jdbc:default:connection");
		PreparedStatement prepStmt = conn.prepareStatement(sqlStatement,
				ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
		System.out.println("sql: "+sqlStatement);
		System.out.println("ph: "+placeHolder);
		StringTokenizer stringToken = new StringTokenizer(placeHolder);
		int i = 1;
		while (stringToken.hasMoreTokens()) {
			prepStmt.setString(i, stringToken.nextToken());
			i++;
		}
		prepStmt.executeUpdate();

		conn.close();
	}
}
